package com.ele.Servlet;

import com.ele.Pojo.Business;
import com.ele.Service.impl.BusinessServiceImpl;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 自己写的按条件查询数据，功能不全
 */
@WebServlet("/searchBusiness")
public class QueryBusinessServlet extends HttpServlet {
    //Servlet
    BusinessServiceImpl businessService =new BusinessServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String account=req.getParameter("account");
        String telephone=req.getParameter("telephone");
        String contact=req.getParameter("contact");
        List<Business> businesses =businessService.queryBusiness(account,telephone,contact);

        Gson gson =new Gson();
        String json =gson.toJson(businesses);

        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().write(json);

    }
}
